<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" name="sub" value="上传">
</form>
<?php
/**
 * User: lie
 * Date: 2020/12/8 13:39
 * Title: 判断上传文件类型
 * Description:
 * Function: preg_match
 * Error:
 */
if ($_POST['sub']) {
    $file = $_FILES['file']['name'];
    if (preg_match('/.jpg/', $file)) {
        echo "上传为图片类型";
    } else {
        if (preg_match("/.rar/", strtolower($file))) {
            echo "上传为压缩包类型";
        } else {
            echo "其他文件类型";
        }
    }

}
